<template>
	<div class="data-list">

		<el-form label-position="left" :inline="true" ref="conditionForm" :model="conditionForm" label-width="70px">
				
			<el-form-item label="系统编码">			
				<el-select v-model="conditionForm.systemCode"  placeholder="===请选择===">
						<el-option v-for="item in options" :label="item.systemCode" :value="item.systemCode">
					    </el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="模块名称">
				<el-input v-model="conditionForm.moduleName"  placeholder="模块名称" ></el-input>
			</el-form-item>
			<el-form-item label="用例名称">
				<el-input v-model="conditionForm.caseName"  placeholder="用例名称" ></el-input>
			</el-form-item>
			
		</el-form>
		
		<el-button type="primary" icon="search"  @click="queryData">查询</el-button>
		<el-button type="primary" icon="search" @click="saveNum">保存</el-button>
		<el-button type="primary" icon="caret-right" @click="execute">执行</el-button>
		
		</br>
		</br>
				
		<el-table :data="tableData" border style="width: 100%" highlight-current-row>
			<el-table-column label="序号"  width="80">
				<template scope="scope">
					<el-input v-if="scope.row.num<99999"  v-model="scope.row.num"></el-input>
					<el-input v-if="scope.row.num==99999" value="" v-model="scope.row.num"></el-input>
				</template>
			</el-table-column>
			<el-table-column prop="systemCode" label="系统编码" width="100">
			</el-table-column>
			<el-table-column prop="systemName" label="系统名称" width="200">
			</el-table-column>
			<el-table-column prop="moduleName" label="系统模块" width="150">
			</el-table-column>
			<el-table-column prop="caseName" label="测试用例名称" >
			</el-table-column>
		</el-table>

		<el-pagination
		      @size-change="pageSizeChange"
		      @current-change="handleCurrentChangePage"
		      :current-page="pag.currentPage"
		      :page-sizes="[10,20, 50, 100, 200]"
		      :page-size="pag.pageSize"
		      layout="->,prev, pager, next, jumper, sizes,total"
		      :total="pag.totalSize">
		 </el-pagination>

	</div>
		
</template>


<script>
	import {
		Message
	} from 'element-ui';
	import {
		Notification
	} from 'element-ui';
	
	
	export default {
		data() {
			return {
				conditionForm: {
					systemCode: '',
					moduleName: '',
					caseName: ''
				},
				options: [],
				tableData: [],
				pageSize: 20,
				totalSize: 0,
				pag:{
					start:0,
					totalSize:0,
					pageSize: 10,
					currentPage:1,
				}
			}
		},
		methods: {
			getPageData(param) {
				debugger
				if(!param || param == {}) {
					var param = {}
				}
				if(!param.hasOwnProperty("pageSize")) {
					param.pageSize = this.pageSize
				}
				if(!param.hasOwnProperty("start")) {
					param.start = 0
				}
				param.currentPage = this.pag.currentPage
				param.pageSize = this.pag.pageSize
				param.start = this.pag.start
				this.$httpExt().post('testCase/selectExecuteCase',
					param 
				).then((response) => {						
					this.tableData = response.result.rows;
					this.pag.totalSize = response.result.totalSize;
				}, (response) => {
					Notification.error({
						title: '异常',
						message: response.msg
					})
				});
			},
			queryData() {
				this.getPageData(this.conditionForm)
			},
			saveNum() {			
				var numArray=[];
				for(var i=0;i<this.tableData.length;i++){
					var obj={
						id:this.tableData[i].id, 
						num:this.tableData[i].num
					};
					numArray.push(obj);
				}
				this.$httpExt().post('testCase/updateNum' ,{
					numArray:numArray
				}).then((response) => {
					if(response.succ='OK'){
						Message({
							message: '保存序号成功！',
							type: 'success'
						});
						this.queryData();
					}else{
						Message({
							message: response.msg,
							type: 'warning'
						});
					}
				}, (response) => {
					Message({
						message: response.msg,
						type: 'warning'
					});
				});
			},
			execute(){
				this.$httpExt().get('testCase/executeCase',{
						'systemCode':this.conditionForm.systemCode
					}).then((response) => {
						
					}, (response) => {
						Notification.error({
							title: '异常',
							message: response.msg
						})
					});
			},
			querySysList(){
				this.$httpExt().get('testCase/sysSelect')
					.then((response) => {
						var condition = response.result
						this.totalSize = condition.length
						this.options = condition
					}, (response) => {
						Notification.error({
							title: '异常',
							message: response.msg
						})
					});
			},
			handleCurrentChangePage(val){//翻页，当前页数给后台
				this.pag.currentPage = val;
				this.pag.start = (val - 1) * this.pag.pageSize;
				this.getPageData();
			},
			pageSizeChange(val){//一页显示多少条
				this.pag.pageSize = val;
				this.getPageData();
			}
			
		},
		mounted() {
			this.querySysList()
		}
	}
</script>


